<template>
  <div class="signBox">
    <form action="javascript:;" method="get">
      <div class="sign">{{$t('userAdmin.info.sign.name')}}</div>
      <div class="signVal"><input type="text" maxlength="100"  autocomplete="off" id="content-s" v-model="userSign"></div>
      <div class="tips" style="height: 20px;" id="tips-s">{{$t('userAdmin.info.sign.tip')}}</div>
      <div class="signSubmit"><input type="submit" :value="$t('userAdmin.info.sign.submit')" id="submit-s" @click="onclickSubOfS"></div>
      <div class="signReset"><input type="reset" :value="$t('userAdmin.info.sign.reset')" id="reset-s" @click="onclickReOfS"></div>
    </form>
  </div>
</template>

<script>
    export default {
        name: "UserAdminInfo-sign",
        data(){
            return{
              userSign:'',
              baseURL:'http://localhost:8081/user/update/sign/'
            }
        },
        mounted(){
            this.axios.post("http://localhost:8081/user/get/sign").then((res)=>{
                if (res.data == "error") {
                    this.$message.error(this.$t('userAdmin.info.sign.serviceUnusual'))
                }else {
                    this.userSign = res.data
                }
            }).catch(
                exception=>{
                    console.log(exception)
                }
            )
        },
        methods:{
            onclickSubOfS() {
                if(this.userSign.trim() == "" || this.userSign.length > 20){
                    document.getElementById("tips-s").style.display="block"
                    document.getElementById("content-s").style.border = "1px solid rgb(250, 37, 0)"
                }else{
                    document.getElementById("tips-s").style.display="none"
                    document.getElementById("content-s").style.border = "1px solid rgb(216, 216, 216)"
                    this.axios.post(this.baseURL+this.userSign).then((res)=>{
                        if (res.data==true){
                            this.successOpt(this.$t('userAdmin.info.sign.optSuccess'))
                        } else {
                            this.failOpt(this.$t('userAdmin.info.sign.optFail'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },
            onclickReOfS() {
                document.getElementById("tips-s").style.display="none"
                document.getElementById("content-s").style.border = "1px solid rgb(216, 216, 216)"
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .signBox{
    margin: 10px auto;
    width: 930px;
    height: 80px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgb(226, 226, 226);
    border-radius: 3px;
    position: relative;
    letter-spacing: 1px;
  }
  .signBox form div{
    float: left;
    height: 35px;
    margin-top: 20px;
  }
  .sign{
    width: 50px;
    margin-left: 25px;
    text-align: center;
    line-height: 35px;
    font-size: 15px;
    color: rgb(80, 80, 80);
  }
  .signVal{
    width: 400px;
    margin-left: 50px;
  }
  .signVal input{
    width: 440px;
    height: 31px;
    border: 1px solid rgb(216, 216, 216);
    background-color: transparent;
    color: rgb(105, 105, 105);
    border-radius: 3px;
    padding-left: 15px;
    transition: 0.3s;
  }
  .signSubmit{
    width: 120px;
    margin-left: 100px;
  }
  .signSubmit input{
    width: 120px;
    height: 35px;
    border: 1px solid rgb(138, 138, 138);
    color: rgb(241, 241, 241);
    border-radius: 3px;
    background-color: cadetblue;
  }
  .signSubmit input:hover{
    background-color: #00988a;
    color: rgb(255, 255, 255);
  }
  .signSubmit input:active{
    background-color: #047c70;
  }
  .signReset{
    width: 120px;
    margin-left: 20px;
  }
  .signReset input{
    width: 120px;
    height: 35px;
    border: 1px solid rgb(216, 216, 216);
    color: rgb(104, 104, 104);
    border-radius: 3px;
    background-color: white;
  }
  .signReset input:hover{
    background-color: rgb(215, 236, 236);
    color: rgb(73, 157, 160);
    border: 1px solid rgb(73, 157, 160);
  }
  .signReset input:active{
    border: 1px solid rgb(0, 0, 0);
  }
  .tips{
    width: 500px;
    font-size: 12px;
    color: rgb(255, 60, 25);
    position: absolute;
    top: 40px;
    left: 124px;
    display: none;
    transition: 0.3s;
  }
</style>
